/**
 * Created by Administrator on 2016/12/8.
 */

$(".form-date").datetimepicker(
    {
        language: "zh-CN",
        weekStart: 1,
        todayBtn: 1,
        autoclose: 1,
        todayHighlight: 1,
        startView: 2,
        minView: 2,
        forceParse: 0,
        format: "yyyy-mm-dd"
    });
$(function () {
    $(".tab-groups input").click(function () {
        $(this).addClass("btn-primary").siblings().removeClass("btn-primary");
    });
});
$(function () {
    $("#qhTable thead tr th").css("text-align", "center");
    $("#qhTables thead tr th").css("text-align", "center");
});

$(function () {
    $(".tab-groups input").click(function () {
        $(this).addClass("btn-primary").siblings().removeClass("btn-primary");
    });
});
$(function () {
    $(".tab-groups input:eq(0)").click(function () {
        $("#filedata").addClass("shows").removeClass("hides").siblings().removeClass("shows").addClass("hides")
    });
    $(".tab-groups input:eq(1)").click(function () {
        $("#userlist").addClass("shows").removeClass("hides").siblings().removeClass("shows").addClass("hides")
    });
    $(".tab-groups input:eq(2)").click(function () {
        $("#bankaccount").addClass("shows").removeClass("hides").siblings().removeClass("shows").addClass("hides")
    });
    $(".tab-groups input:eq(3)").click(function () {
        $("#fundaccount").addClass("shows").removeClass("hides").siblings().removeClass("shows").addClass("hides")
    })
});
function newMain() {
    var index = layer.open({
        type: 2,
        title: false,
        shadeClose: true,
        shade: false,
        maxmin: false, //开启最大化最小化按钮
        area: ['773px', '500px'],
        content: 'newWork/newMain.html'
    });
}
function newSeed() {
    var index = layer.open({
        type: 2,
        title: false,
        shadeClose: true,
        shade: false,
        maxmin: false, //开启最大化最小化按钮
        area: ['773px', '500px'],
        content: 'newWork/newSeed.html'
    });
}
function newBank() {
    var index = layer.open({
        type: 2,
        title: false,
        shadeClose: true,
        shade: false,
        maxmin: false, //开启最大化最小化按钮
        area: ['773px', '500px'],
        content: 'bankAccount/newBank.html'
    });
}
function newper() {
    var index = layer.open({
        type: 2,
        title: false,
        shadeClose: true,
        shade: false,
        maxmin: false, //开启最大化最小化按钮
        area: ['773px', '500px'],
        content: 'personAccount/newper.html'
    });
}
//启用状态设置
$(function () {
    var i = 0;
    $(".switchs").on("click", function () {
        i++;
        if (i % 2 == 1) {
            $("#switch").text("已关闭");
        } else {
            $("#switch").text("已开启");
        }
    })
});

/* 新增用户档案资料  保存并下一步 */
$(".confirm").on("click", function () {
    var message = {};
    $("#filedata [data-name]").each(function (i, element) {
        if ($(element).attr('data-name') == 'sex') {
            message.sex = $(element).children('label').children('input').prop('checked') ? "0" : "1";
        } else if ($(element).attr('data-name') == 'isValid') {
            message.isValid = $("#switch").text() == '已关闭' ? "0" : "1";
        }else if ($(element).attr('data-name') == 'userAge'){
            message.userAge = calculateAge();
        }else {
            //console.log($(element).val());
            message[$(element).attr('data-name')] = $(element).val();
        }
    });
    $.ajax({
        type: "post",
        url: "http://192.168.59.104:8081/shixiaobao/console/addPersonalUserInfo",
        data: message
    });
    console.log(message);
});
//实现年龄
calculateAge()
function calculateAge() {
    var newTime = new Date().getFullYear();
    $(".Age").change(function () {
       var age =newTime - $(this).val().split("-")[0];
        $(".Ageval").val(age);
    })
    return $(".Ageval").val();
}
// 提示
hintVal();
function hintVal() {
    $(".hint").each(function(index,ipt){
        $(ipt).blur(function(){
            !$(ipt).val()?
                $(".warning").eq(index).show():
                $(".warning").eq(index).hide();
        })
    })
}

/* 账号列表  消息  */
$("#qhTable").bootstrapTable({
    height: "900px",
    url: "data1.json",
    // onClickRow: function (row) {
    //     console.log(row);
    //     layer.open({
    //         type: 2,
    //         title: false,
    //         shadeClose: true,
    //         shade: false,
    //         maxmin: false, //开启最大化最小化按钮
    //         area: ['773px', '500px'],
    //         content: `newWork/accEdit.html?userName=${row.userName}&headProtrait=${row.headProtrait}&accountType=${row.accountType}&nickName=${row.nickName}&idCardFront=${row.idCardFront}&idCardBack=${row.idCardBack}&regTime=${row.regTime}&phone=${row.phone}`
    //     });
    //}
});
function lookClick(index) {
    var row = $("#qhTable").data("bootstrap.table").data[index];
    // $("#qhTable").bootstrapTable('uncheckAll');
    // $("#qhTable").bootstrapTable('check',index);
    // var row2=$("#qhTable").bootstrapTable('getSelections');
    // console.log(row);
    // console.log(row2)
    // $(element).attr('data-name').each(function (row) {
    layer.open({
        type: 2,
        title: false,
        shadeClose: true,
        shade: false,
        maxmin: false, //开启最大化最小化按钮
        area: ['773px', '500px'],
        content: `newWork/accLook.html?userName=${row.userName}&headProtrait=${row.headProtrait}&accountType=${row.accountType}&nickName=${row.nickName}&idCardFront=${row.idCardFront}&idCardBack=${row.idCardBack}&regTime=${row.regTime}&phone=${row.phone}&isValid=${row.isValid}`
    })
    // });
}
function editClick(index) {
    var row = $("#qhTable").data("bootstrap.table").data[index];
    console.log(row);
    layer.open({
        type: 2,
        title: false,
        shadeClose: true,
        shade: false,
        maxmin: false, //开启最大化最小化按钮
        area: ['773px', '500px'],
        content: `newWork/accEdit.html?userName=${row.userName}&headProtrait=${row.headProtrait}&accountType=${row.accountType}&nickName=${row.nickName}&idCardFront=${row.idCardFront}&idCardBack=${row.idCardBack}&regTime=${row.regTime}&phone=${row.phone}&isValid=${row.isValid}`
    });
}

/* 新增银行 对公账户 */
// function editClick(index) {
//     var row = $("#qhTables").data("bootstrap.table").data[index];
//     console.log(row)
//     layer.open({
//         type: 2,
//         title: false,
//         shadeClose: true,
//         shade: false,
//         maxmin: false, //开启最大化最小化按钮
//         area: ['773px', '500px'],
//         content: `bankAccount/editBank.html?userName=${row.userName}&headProtrait=${row.headProtrait}&accountType=${row.accountType}&nickName=${row.nickName}&idCardFront=${row.idCardFront}&idCardBack=${row.idCardBack}&regTime=${row.regTime}&phone=${row.phone}`
//     });
// }

function totalFormatter(value, row, index) {
    return "<div class='edit-del'><input type='button' class='btn btn-primary edit' onclick='lookClick(" + index + ")' value='查看'>" +
        "<input type='button' class='btn btn-primary del' value='编辑' onclick='editClick(" + index + ")'></div>"
}


function totalFormatter(value, row, index) {
    return "<div class='edit-del'><input type='button' class='btn btn-primary edit' onclick='lookClick(" + index + ")' value='查看'>" +
        "<input type='button' class='btn btn-primary del' value='编辑' onclick='editClick(" + index + ")'></div>"
}

function myQueryParams(params) {
    params["pageNum"] = (params.offset / params.limit) + 1;
    params.pageSize = params.limit;
    params.derection = "asc";
    params.sort = "id";
    params.orderCode = $("#orderCode").val() + "";
    return params;
}

function responseHandler(res) {
    console.log(res);
    var needData = {
        rows: res.data.list
    };
    return needData;
}








